/************************************
 * created by Tonk (tonk@ctonk.com) *
 ************************************/

// object_base.cpp

#include "definitions.h"
#include "object.h"
#include "stringutil.h"
#include <fstream>

/////////////////////////////////////////// base object class /////////////////////////////////////////// 

int Object::numObjects = 0;

Object::Object() {
	_vnum = 0;
	_type = TRASH;
	_flags = 0;
	numObjects++;
}

Object::Object( Object& it ) {
	_vnum = it.getVnum();
	_type = it.getType();
	_flags = it.getFlags();
	_keywords = it.getKeywords();
	_short = it.getShort();
	_long = it.getLong();
	_desc = it.getDesc();
}

Object::~Object() {
	numObjects--;
}

Object& Object::operator = ( Object& it ) {
	_vnum = it.getVnum();
	_type = it.getType();
	_flags = it.getFlags();
	_keywords = it.getKeywords();
	_short = it.getShort();
	_long = it.getLong();
	_desc = it.getDesc();
	return *this;
}

void Object::copyObjectData( Object& it ) { // private
	setVnum( it.getVnum() );
	setType( it.getType() );
	setFlags( it.getFlags() );
	setKeywords( it.getKeywords() );
	setShort( it.getShort() );
	setLong( it.getLong() );
	setDesc( it.getDesc() );
}

void Object::setVnum( int vnum ) {
	_vnum = vnum;
	return;
}

int Object::getVnum() {
	return _vnum;
}

void Object::setType( OBJECT_TYPE type ) {
	_type = type;
	return;
}

OBJECT_TYPE Object::getType() {
	return _type;
}

void Object::setWeight( int weight ) {
	_weight = weight;
	return;
}

int Object::getWeight() {
	return _weight;
}

void Object::setFlags( int flags ) {
	_flags = flags;
}

int Object::getFlags() {
	return _flags;
}

void Object::setKeywords( std::string keywords ) {
	_keywords = keywords;
	return;
}

std::string& Object::getKeywords() {
	return _keywords;
}

void Object::setShort( std::string short_desc ) {
	_short = short_desc;
	return;
}

std::string Object::getShort() {
	return _short;
}

void Object::setLong( std::string long_desc ) {
	_long = long_desc;
	return;
}

std::string Object::getLong() {
	return _long;
}

void Object::setDesc( std::string desc ) {
	_desc = desc;
	return;
}

std::string& Object::getDesc() {
	return _desc;
}

void Object::oSave( std::ofstream& save ) {
	save << "\n**OBJECT\n";

	save << _vnum << ' ' << stringType( getType() ) << ' ' << _flags << ' ' << _keywords << '\n';
	save << _short << '\n' << _long << '\n' << _desc << "$\n";

	return;
}

Object* Object::getNewObject( OBJECT_TYPE type ) {
	switch ( type ) {
		case ACCESSORY:
			return new Accessory;
		case ARMOR:
			return new Armor;
		case BODY_PART:
			return new Body_Part;
		case CLOTHING:
			return new Clothing;
		case COIN:
			return new Coin;
		case CONTAINER:
			return new Container;
		case FOOD:
			return new Food;
		case FURNITURE:
			return new Furniture;
		case JEWELRY:
			return new Jewelry;
		case SCROLL:
			return new Scroll;
		case TRASH:
			return new Trash;
		case WAND:
			return new Wand;
		case WEAPON:
			return new Weapon;
		default:
			std::cerr	<< "Object::getNewObject() switch default hit (with type == \""
						<< type << "\") in file " << __FILE__ << " at line " << __LINE__ << "\n";
			return NULL;
	}
}

std::string Object::objectDisplay( std::string subTypeDisplay ) {
	std::string buf;

	buf << "{Cvnum:{x " << getVnum() << "\n\r";
	buf << "{Ctype:{x " << Object::stringType( getType() ) << "\n\r";
	buf << "{Cflags:{x " << getFlags() << "\n\r";
	buf << "{Ckeywords:{x " << getKeywords() << "\n\r";
	buf << "{Cshort:{x " << getShort() << "\n\r";
	buf << "{Clong:{x " << getLong() << "\n\r";
	buf << subTypeDisplay;
	buf << "{CDescription:{x " << getDesc() << "\n\r";

	return buf;
}

std::string Object::stringType( OBJECT_TYPE type ) {
	switch ( type ) {
		case ACCESSORY: return "accessory";
		case ARMOR: return "armor";
		case BODY_PART: return "body_part";
		case CLOTHING: return "clothing";
		case COIN: return "coin";
		case CONTAINER: return "container";
		case DRINK: return "drink";
		case FOOD: return "food";
		case FURNITURE: return "furniture";
		case JEWELRY: return "jewlery";
		case SCROLL: return "scroll";
		case TRASH: return "trash";
		case WAND: return "wand";
		case WEAPON: return "weapon";
		default: return "{Rerror{x";
	}
}

OBJECT_TYPE Object::objectType( std::string type ) {
	if ( type == "accessory" )
		return ACCESSORY;
	else if ( type == "armor" )
		return ARMOR;
	else if ( type == "body_part" )
		return BODY_PART;
	else if ( type == "clothing" )
		return CLOTHING;
	else if ( type == "coin" )
		return COIN;
	else if ( type == "container" )
		return CONTAINER;
	else if ( type == "drink" )
		return DRINK;
	else if ( type == "food" )
		return FOOD;
	else if ( type == "furniture" )
		return FURNITURE;
	else if ( type == "jewlery" )
		return JEWELRY;
	else if ( type == "scroll" )
		return SCROLL;
	else if ( type == "trash" )
		return TRASH;
	else if ( type == "wand" )
		return WAND;
	else if ( type == "weapon" )
		return WEAPON;
	else
		return OT_ERROR;
}
